define(function (require, exports, module) {
    require("apps/pbom/page.css");
    require("apps/grid");

    exports.init = function (ctx, uuid, config) {

        var pageListComponent = new $.PageTreeListComponent(uuid, {
            pagination:false,
            view: {
                grid: "grid",
                colbar: "user_list_btn"
            },
            configs: {
                gridTitle: "工艺设计结构列表",
                gridUrl: ctx + "/app/api/pbom/list?id=" + config.id,
                idField: "id",
                treeField: "pName",
                gridColumns: [
                    {
                        field: 'id',
                        checkbox: true
                    },
                    {
                        field: 'temp1',
                        hidden: true
                    },
                    {
                        field: 'pName',
                        title: '名称',
                        width: 100,
                        align: 'left'
                    },
                    {
                        field: 'code',
                        title: '编码',
                        width: 100,
                        align: 'left'
                    },
                    {
                        field: 'number',
                        title: '数量（件）',
                        width: 50,
                        align: 'left'
                    },
                    {
                        field: 'bomType',
                        title: '制造分类',
                        width: 100,
                        align: 'left'
                    },
                    {
                        field: '_queryNumber',
                        title: '匹配的工件',
                        width: 100,
                        align: 'left',
                        formatter: function (value, row, index) {
                            return "总数：" + row.suitAll + "，未装配：" + row.nonBuild;
                        }
                    },
                    {
                        field: 'remark',
                        title: '备注',
                        hidden: true,
                        width: 50,
                        align: 'left'
                    },
                    {
                        field: 'status',
                        title: '状态',
                        width: 50,
                        align: 'left',
                        formatter: function (value, row, index) {
                            if (value == "PUBLISH") {
                                return "已发布";
                            } else if (value == "UN_PUBLISH") {
                                return "未发布";
                            } else {
                                return "已废弃";
                            }
                        }
                    }
                ],
                onExpand: function (row) {
                    if (row.children == undefined) {
                        pageListComponent.grid.treegrid("loadChildren", {
                            url: ctx + "/app/api/pbom/children",
                            row: row
                        });
                    }
                }
            },
            events: {
                renderColBarBefore: function (key, row) {
                    return true;
                },
                onClickColBtn: function (context, btn, row) {
                    switch (btn.key) {
                        case "view":
                            whenView(context, row);
                            break;
                        default :
                            break;
                    }
                }
            }
        });

        function whenView(context, row) {
            context.detail("工艺设计结构详情查看", row);
        }
    }
});